﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AwesomeEnginePC.SQL;
using AwesomeEnginePC.Extentions;

using System.Data.SqlClient;
using System.Data;

namespace AE.PC.Test.SQLTesting
{
    public class MSDataAccessor : MsSqlConnector
    {
        public MSDataAccessor(string hostName, string database, string userName, string password)
            : base(hostName, database, userName, password)
        {
        }

        public MSDataAccessor(SqlConnection conn)
            : base(conn)
        {
        }

        public List<string> GetAllAuthorNames()
        {
            List<string> names = new List<string>();

            var result = ExecUseDataSet("pubs_GetAllAuthorNames",
                (c) =>
                {
                   
                },
                (ds) =>
                {
                    ds.Tables[0].Rows.OfType<DataRow>().ToList().ForEach((x) =>
                        {
                            names.Add(x.Field<string>("Name"));
                        });

                });

            if (result != SQLQueryResult.Sucessful)
            {
                throw new Exception("died");
            }

            return names;
        }

        public void SetOrderQuanity(string orderNumber, int qty)
        {
            var result = Exec("pubs_SetOrderQuantity",
                (c) =>
                {
                    c.AddParam("@OrderNumber", orderNumber);
                    c.AddParam("@Quantity", qty);
                });

            if (result != SQLQueryResult.Sucessful)
            {
                throw new Exception("died");
            }
        }
    }
}
